package com.itany.corejava.day17;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TestClientA {

    public static void main(String[] args) {

        Socket s=null;

        BufferedReader br=null;

        try{

            // s=new Socket("10.0.3.108",8888);

            // s=new Socket("127.0.0.1",8888);

            s=new Socket("localhost",8888);


            br=new BufferedReader(
                    new InputStreamReader(
                            s.getInputStream()
                    )
            );

            System.out.println("++++++++++++");
            //使线程处于阻塞状态，当服务器端发送数据时回到就绪状态
            String message=br.readLine();
            System.out.println("------------");

            System.out.println(message);
        }catch (Exception e){
            e.printStackTrace();
        }finally{
            if(br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(s!=null){
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
